package ltd.dujiabao.mavenLocalInstaller.util;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author : DuJiabao
 * @Project : mavenLocalInstaller
 * @Time : 2021/9/29 22:47
 * @Desc :
 */
public class CmdUtils {
    /**
     * windows 执行 cmd命令
     */
    public static String exec(String cmd) {
        InputStream inputStream = null;
        String result = null;
        try {
            Process process = new ProcessBuilder("cmd", "/c", cmd).start();
            inputStream = process.getInputStream();
            result = StreamUtils.output(inputStream, "GBK");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            StreamUtils.close(inputStream);
        }

        return result;
    }
}
